fix(admin): match sidebar active state when a plugin page path is "/" - #3008
Open
marks-zyz wants to merge 2 commits into
Open
fix(admin): match sidebar active state when a plugin page path is "/"#3008marks-zyz wants to merge 2 commits into
marks-zyz wants to merge 2 commits into
Conversation
A plugin admin page declared with path "/" builds the sidebar target as /plugins/<id>/, but the router navigates to the same URL without the trailing slash, so isItemActive never matched and the item stayed unhighlighted. This hits the shipped forms plugin (its "Forms" page). Normalize the trailing slash on both sides, keeping "/" exact for the admin root, and cover the case in the Sidebar tests.
🦋 Changeset detectedLatest commit: e015c29 The changes in this PR will be included in the next version bump. This PR includes changesets to release 17 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
A plugin admin page declared with
path: "/"never gets the active state in the sidebar. The link works and the page renders; only the highlight is missing, so the sidebar shows no selected item while you are on that page. This affects the shipped@emdash-cms/plugin-forms, whose first page is declared as{ path: "/", label: "Forms" }.Sidebar.tsxbuilds the target by concatenation (/plugins/${pluginId}${page.path}), sopath: "/"yields/plugins/<id>/with a trailing slash, while the router navigates to/plugins/<id>.isItemActivecompared the two exactly, so the item could never match.This normalizes the trailing slash on both sides before comparing, keeping
"/"exact for the admin root. The fix is in the comparison rather than in the item builder, so it covers any nav item whose target ends in a slash, not just plugin pages.Closes #2988
Type of change
Checklist
pnpm typecheckpassespnpm lintpassespnpm testpasses (or targeted tests for my change)pnpm formathas been runEnvironment note, so the three unchecked boxes above are not a mystery: I could not run the repo's own
typecheck,lintandtestlocally. A scoped install (pnpm install --filter @emdash-cms/admin...) leaves the other workspace packages unbuilt, sopnpm typecheckinpackages/adminfails on@emdash-cms/blocks,@emdash-cms/plugin-typesand@emdash-cms/registry-client— pre-existing resolution errors unrelated to this change, and CONTRIBUTING sayspnpm buildis required first. The admin suite also runs in browser mode, which I did not set up. What I did run is below. CI is the source of truth here.AI-generated code disclosure
Screenshots / test output
Both screenshots are from EmDash 0.36.0 running in
astro dev, same sidebar, same session. The site has two plugins with admin pages: the shipped forms plugin (path: "/", hits the bug) and a local email provider that works around it withpath: "/status".Before — the forms plugin page is open (
/plugins/emdash-forms), and no sidebar item is highlighted:After — the same sidebar with a page whose path has a segment (
/plugins/ses-email/status), where the highlight appears as expected. This is the state the patch gives back topath: "/"pages:The rendered pixels do not change; what changes is which item receives the active state. The measurement behind the screenshots, reading
data-activeon the sidebar anchors in the page:Targeted verification of the new comparison, including the cases the existing behavior must keep:
Four of these are added to the existing
isItemActiveblock inpackages/admin/tests/components/Sidebar.test.tsx.